const baseUrl = 'https://test.taiyi.eday.ink';
const request = (url, method = "GET", data = {}, header = {}) => {
  const token = wx.getStorageSync('token');
  const reqHeader = {
    "content-type": "application/json",
    ...(token ? { Authorization: `Bearer ${token}` } : {}),
    ...header,
  };
  return new Promise((resolve, reject) => {
    wx.request({
      url: baseUrl + url,
      method,
      data,
      header: reqHeader,
      success: (res) => {
        resolve(res.data);
      },
      fail: (err) => {
        reject(err);
      },
    });
  });
};
const get = (url, data, header) => request(url, "GET", data, header);
const post = (url, data, header) => request(url, "POST", data, header);
export { request, get, post };
